<?php
/**
 * Created by PhpStorm.
 * User: lee
 * Date: 2018/3/30
 * Time: 下午1:59
 */


namespace Biz\service\trade;

use Biz\model\OperateLog as mOperateLog;
use Biz\model\trade\Order as mOrder;
use Biz\model\trade\OrderPackage as mOrderPackage;
use Biz\model\trade\OrderRefund as mOrderRefund;
use Biz\model\trade\ShopCourier as mShopCourier;
use Biz\module\Classes\adm\OrderRefund as clsAdmOrderRefund;
use Biz\module\Classes\adm\OrderRefundList;
use Biz\module\Classes\adm\OrderRefundSearch as clsAdmOrderRefundSearch;
use Biz\module\Classes\adm\OrderRightList;
use Biz\module\Classes\adm\OrderRightsSearch as clsAdmOrderRightsSearch;
use Biz\module\Classes\mgt\OrderRefund as clsMgtOrderRefund;
use Biz\module\Classes\OrderGroupBuy as clsOrderGroupBuy;
use Biz\module\Classes\OrderRefund as clsOrderRefund;
use Biz\module\Classes\OrderRefundList as clsOrderRefundList;
use Biz\service\esSearch\OrderRefund as searchOrderRefund;
use Biz\service\OperateLog as sOperateLog;
use Doraemon\model\Member;
use Doraemon\service\search\AdmUserSearch;
use Doraemon\tools\Log as tLog;
/**
 * @deprecated
 */
class OrderRefund
{

    //获取退款原因
    public static function getRefundReasonList($orderNo, $skuId = null, $typeRefund = null, $receiptStatus = null)
    {
        $orderInfo = mOrder::getOrderInfo($orderNo);

        $mainStatus = $orderInfo['status'];

        if ($orderInfo['is_package_delivery'] == mOrder::IS_PACKAGE_DELIVERY_YES) {
            if (!is_null($skuId)) {
                $check = mOrderPackage::checkSkuIdsDelivery($orderNo, [$skuId]);

                if ($check) {
                    $mainStatus = mOrder::STATUS_SEND_OUT;
                } else {
                    $mainStatus = mOrder::STATUS_WAIT_SEND;
                }
            }


            //如果是门店自提则另需判断
            $packageInfo = mOrderPackage::getFirstPackageInfo($orderNo);

            if ($packageInfo['express_company'] == mShopCourier::SELF_LIFTING_NAME) {
                if ($orderInfo['status'] == mOrder::STATUS_WAIT_SEND) {
                    $mainStatus = mOrder::STATUS_WAIT_SEND;
                }
            }
        }


        $clsOrderRefund = new clsOrderRefund();

        $reasonList = $clsOrderRefund->getRefundReasonList($mainStatus, $typeRefund, $receiptStatus);


        //如果是确认收货超过7天，则不显示7天内退换货的选项
        $confirmTime = function ($confirmTime) use (&$reasonList) {
            $timeStamp = strtotime($confirmTime);
            $addNDaysTimeStamp = $timeStamp + mOrder::MAX_REFUND_GOODS_DAYS_WITH_NO_REASON;

            $reasonList = array_column($reasonList, null, "id");

            if ($timeStamp > 0 && $addNDaysTimeStamp < time()) {
                if (isset($reasonList[35])) {
                    unset($reasonList[35]);
                }
                if (isset($reasonList[40])) {
                    unset($reasonList[40]);
                }
            }
            $reasonList = array_values($reasonList);
        };

        $confirmTime($orderInfo['confirm_time']);


        return $reasonList;
    }

    //获取所有退款原因
    public static function getAllRefundReasonList()
    {
        $result = mOrderRefund::getAllRefundReasonList();

        return $result;
    }


    public static function getRefundSkuInfo($uid, $orderNo, $skuId, $reason = -1)
    {
        try {
            $clsOrderRefund = new clsOrderRefund();

            $info = $clsOrderRefund->getRefundSkuInfo($uid, $orderNo, $skuId, $reason);

            return $info;
        } catch (\Exception $e) {
            throw $e;
        }

    }

    public static function calRefund($uid, $orderNo, $skuId, $refundOrderNo = '', $refundAmount = null)
    {
        try {
            $clsOrderRefund = new clsOrderRefund();


            $data = $clsOrderRefund->calRefund($uid, $orderNo, $skuId, $refundOrderNo, $refundAmount);

            return $data;
        } catch (\Exception $e) {
            throw $e;
        }

    }

    public static function applyRefund($uid, $orderNo, $skuId, $data)
    {
        try {
            $result = mOrderRefund::action(function () use ($uid, $orderNo, $skuId, $data) {
                $clsOrderRefund = new clsOrderRefund();

                $result = $clsOrderRefund->applyRefund($uid, $orderNo, $skuId, $data);

                return $result;
            });

            if ($result !== false) {
                return [
                    'refund_order_no' => $result,
                ];
            }
        } catch (\Exception $e) {

            tLog::refund_refund_warning('申请退款出现异常', [
                'params' => [
                    'uid' => $uid,
                    'order_no' => $orderNo,
                    'sku_id' => $skuId,
                    'data' => $data
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }

    public static function changeRefund($uid, $refundOrderNo, $data)
    {
        try {
            mOrderRefund::action(function () use ($uid, $refundOrderNo, $data) {
                $clsOrderRefund = new clsOrderRefund();

                $clsOrderRefund->changeRefund($uid, $refundOrderNo, $data);

            });

        } catch (\Exception $e) {

            tLog::refund_refund_warning('修改退款申请出现异常', [
                'params' => [
                    'uid' => $uid,
                    'refund_order_no' => $refundOrderNo,
                    'data' => $data
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }

    public static function mgtAgreeRefund($shopId, $refundOrderNo, $addressId = 0, $isSys = false)
    {
        try {
            $result = mOrderRefund::action(function () use ($shopId, $refundOrderNo, $addressId, $isSys) {
                $clsMgtOrderRefund = new clsMgtOrderRefund();

                $result = $clsMgtOrderRefund->agreeRefund($shopId, $refundOrderNo, $addressId, $isSys);

                return $result;
            });

            if ($result !== false) {
                //记录OPERATE_LOG
                sOperateLog::record(mOperateLog::TYPE_REFUND_ORDER_MGT_AGREE_REFUND, $shopId, $refundOrderNo, [], []);
            }


        } catch (\Exception $e) {

            tLog::refund_refund_warning('同意退款出现异常', [
                'params' => [
                    'shop_id' => $shopId,
                    'refund_order_no' => $refundOrderNo,
                    'addressid' => $addressId,
                    'issys' => (int)$isSys
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }

    public static function mgtRejectRefund($shopId, $refundOrderNo, $data)
    {
        try {
            $result = mOrderRefund::action(function () use ($shopId, $refundOrderNo, $data) {
                $clsMgtOrderRefund = new clsMgtOrderRefund();

                $clsMgtOrderRefund->rejectRefund($shopId, $refundOrderNo, $data);

            });

            if ($result !== false) {
                //记录OPERATE_LOG
                sOperateLog::record(mOperateLog::TYPE_REFUND_ORDER_MGT_REJECT_REFUND, $shopId, $refundOrderNo, [], []);
            }

        } catch (\Exception $e) {

            tLog::refund_refund_warning('商家拒绝退款出现异常', [
                'params' => [
                    'shop_id' => $shopId,
                    'refund_order_no' => $refundOrderNo,
                    'data' => $data,
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }

    public static function mgtFillRightsProof($shopId, $refundOrderNo, $data)
    {
        try {
            $result = mOrderRefund::action(function () use ($shopId, $refundOrderNo, $data) {
                $clsMgtOrderRefund = new clsMgtOrderRefund();

                $clsMgtOrderRefund->fillRightsProof($shopId, $refundOrderNo, $data);

            });

            if ($result !== false) {
                //记录OPERATE_LOG
                sOperateLog::record(mOperateLog::TYPE_REFUND_ORDER_MGT_FILL_RIGHTS_PROOF, $shopId, $refundOrderNo, [], $data);
            }

        } catch (\Exception $e) {

            tLog::refund_rights_warning('商家填写维权凭证出现异常', [
                'params' => [
                    'shop_id' => $shopId,
                    'refund_order_no' => $refundOrderNo,
                    'data' => $data,
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }

    public static function mgtProlongReceipt($shopId, $refundOrderNo)
    {
        try {
            $result = mOrderRefund::action(function () use ($shopId, $refundOrderNo) {
                $clsMgtOrderRefund = new clsMgtOrderRefund();

                $clsMgtOrderRefund->prolongReceipt($shopId, $refundOrderNo);

            });

            if ($result !== false) {
                //记录OPERATE_LOG
                sOperateLog::record(mOperateLog::TYPE_REFUND_ORDER_MGT_PROLONG_RECEIPT, $shopId, $refundOrderNo, [], []);
            }

        } catch (\Exception $e) {

            tLog::refund_refund_warning('商家延长退货的收货时间出现异常', [
                'params' => [
                    'shop_id' => $shopId,
                    'refund_order_no' => $refundOrderNo,
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }


    public static function mgtConfirmRefund($shopId, $refundOrderNo, $isSys = false)
    {
        try {
            $result = mOrderRefund::action(function () use ($shopId, $refundOrderNo, $isSys) {
                $clsMgtOrderRefund = new clsMgtOrderRefund();

                $clsMgtOrderRefund->confirmRefund($shopId, $refundOrderNo, $isSys);

            });

            if ($result !== false) {
                //记录OPERATE_LOG
                sOperateLog::record(mOperateLog::TYPE_REFUND_ORDER_MGT_CONFIRM_REFUND, $shopId, $refundOrderNo, [], []);
            }

        } catch (\Exception $e) {

            tLog::refund_refund_warning('商家确认退款出现异常', [
                'params' => [
                    'shop_id' => $shopId,
                    'refund_order_no' => $refundOrderNo,
                    'issys' => (int)$isSys
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }

    public static function cancelRefund($uid, $refundOrderNo, $isSys = false)
    {
        try {
            mOrderRefund::action(function () use ($uid, $refundOrderNo, $isSys) {
                $clsOrderRefund = new clsOrderRefund();

                $clsOrderRefund->cancelRefund($uid, $refundOrderNo, $isSys);


                //取消维权，有可以取消的维权就取消，没有则不取消也不处理异常
                try {
                    $clsOrderRefund->cancelRights($uid, $refundOrderNo, false);
                } catch (\Exception $e) {

                }
            });

        } catch (\Exception $e) {

            tLog::refund_refund_warning('取消退款出现异常', [
                'params' => [
                    'uid' => $uid,
                    'refund_order_no' => $refundOrderNo,
                    'issys' => (int)$isSys
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }

    public static function fillLogistics($uid, $refundOrderNo, $data)
    {
        try {
            mOrderRefund::action(function () use ($uid, $refundOrderNo, $data) {
                $clsOrderRefund = new clsOrderRefund();

                $clsOrderRefund->fillLogistics($uid, $refundOrderNo, $data);

            });

        } catch (\Exception $e) {

            tLog::refund_refund_warning('用户填写退货物流信息出现异常', [
                'params' => [
                    'uid' => $uid,
                    'refund_order_no' => $refundOrderNo,
                    'data' => $data
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }

    public static function cancelRights($uid, $refundOrderNo)
    {
        try {
            mOrderRefund::action(function () use ($uid, $refundOrderNo) {
                $clsOrderRefund = new clsOrderRefund();

                $clsOrderRefund->cancelRights($uid, $refundOrderNo);

            });

        } catch (\Exception $e) {

            tLog::refund_rights_warning('用户取消维权出现异常', [
                'params' => [
                    'uid' => $uid,
                    'refund_order_no' => $refundOrderNo,
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }

    public static function launchRights($uid, $refundOrderNo, $data)
    {
        try {
            mOrderRefund::action(function () use ($uid, $refundOrderNo, $data) {
                $clsOrderRefund = new clsOrderRefund();

                $clsOrderRefund->launchRights($uid, $refundOrderNo, $data);

            });

        } catch (\Exception $e) {

            tLog::refund_rights_warning('用户发起维权出现异常', [
                'params' => [
                    'uid' => $uid,
                    'refund_order_no' => $refundOrderNo,
                    'data' => $data
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }

    /**
     * 退款详情
     * @param $uid
     * @param $refundOrderNo
     * @return array
     * @throws \Exception
     */
    public static function getRefundDetail($uid, $refundOrderNo, $reason = -1)
    {
        $result = (new clsOrderRefund())->getDetail($refundOrderNo, $uid, $reason);
        return $result;
    }

    /**
     * 退款列表
     * @param $uid
     * @param $page
     * @param $pageSize
     * @return array
     */
    public static function getRefundList($uid, $page, $pageSize)
    {
        $list = (new clsOrderRefundList())->getList($uid, $page, $pageSize);
        return $list;
    }

    /**
     * 协商史
     * @param $refundOrderNo
     * @return array
     */
    public static function getRefundLogList($uid, $refundOrderNo)
    {
        $list = (new clsOrderRefund())->getRefundLogList($uid, $refundOrderNo);
        return $list;
    }

    public static function fillRightsProof($uid, $refundOrderNo, $data)
    {
        try {
            mOrderRefund::action(function () use ($uid, $refundOrderNo, $data) {
                $clsOrderRefund = new clsOrderRefund();

                $clsOrderRefund->fillRightsProof($uid, $refundOrderNo, $data);

            });

        } catch (\Exception $e) {

            tLog::refund_rights_warning('用户填写维权凭证出现异常', [
                'params' => [
                    'uid' => $uid,
                    'refund_order_no' => $refundOrderNo,
                    'data' => $data
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }


    /**
     * 商家退款列表
     * @param $shopId
     * @param $params
     * @param $page
     * @param $pageSize
     * @return array
     */
    public static function  mgtGetRefundList($shopId, $params, $page, $pageSize)
    {
        if (is_null($page) || $page < 1) {
            $page = 1;
        }
        $params['shop_id'] = $shopId;
        $list = searchOrderRefund::getList($params, searchOrderRefund::SCENES_SELLER_ORDER_REFUND, $params['order_type'], $page, $pageSize, 'refund_order_no');
        $orderList = OrderRefundList::sellerRefundList($list, isset($params['order_type'])?$params['order_type']:0);
        return $orderList;

//        $limit = [($page - 1) * $pageSize, $pageSize];
//        $params['shop_id'] = $shopId;
//        $orders = (new clsMgtRefundList($params, $limit))->refundList();
//        $data = [
//            'all_count' => $orders['all_count'],
//            'list' => $orders['list'],
//            'count' => $orders['count']
//        ];
//        return $data;
    }

    /**
     * 商家退款详情
     * @param $refundOrderNo
     * @param $shopId
     * @return array
     * @throws \Exception
     */
    public static function mgtGetDetail($refundOrderNo, $shopId)
    {
        $result = (new clsMgtOrderRefund())->getDetail($refundOrderNo, $shopId);
        return $result;
    }

    /**
     * 商家退款维权操作记录
     * @param $refundOrderNo
     * @param $shopId
     * @return array
     */
    public static function mgtGetRefundLogList($refundOrderNo, $shopId)
    {
        $list = (new clsMgtOrderRefund())->getLogList($refundOrderNo, $shopId);
        return $list;
    }

    /**
     * 商家维权列表
     * @param $shopId
     * @param $params
     * @param $page
     * @param $pageSize
     * @return array
     */
    public static function mgtGetRightsList($shopId, $params, $page, $pageSize)
    {
        if (is_null($page) || $page < 1) {
            $page = 1;
        }
        $params['shop_id'] = $shopId;
        $params['rights_status'] = $params['status'];
        unset($params['status']);
        $list = searchOrderRefund::getList($params, searchOrderRefund::SCENES_SELLER_ORDER_RIGHT, $params['order_type'], $page, $pageSize, 'refund_order_no');
        $orderList = OrderRightList::sellerRightList($list, $params['order_type']);
        return $orderList;

//        if (is_null($page) || $page < 1) {
//            $page = 1;
//        }
//        $limit = [($page - 1) * $pageSize, $pageSize];
//        $params['shop_id'] = $shopId;
//        $orders = (new clsMgtRightsList($params, $limit))->rightsList();
//        $data = [
//            'all_count' => $orders['all_count'],
//            'list' => $orders['list'],
//            'count' => $orders['count']
//        ];
//        return $data;
    }

    /**
     * 商家维权详情
     * @param $refundOrderNo
     * @param $shopId
     * @return array
     * @throws \Exception
     */
    public static function mgtGetRightsDetail($refundOrderNo, $shopId)
    {
        $result = (new clsMgtOrderRefund())->getRightsDetail($refundOrderNo, $shopId);
        return $result;
    }

    public static function admRightsInto($adminUid, $refundOrderNo)
    {
        try {
            $result = mOrderRefund::action(function () use ($adminUid, $refundOrderNo) {
                $clsAdmOrderRefund = new clsAdmOrderRefund();

                $clsAdmOrderRefund->rightsInto($adminUid, $refundOrderNo);

            });

            if ($result !== false) {
                //记录OPERATE_LOG
                sOperateLog::record(mOperateLog::TYPE_REFUND_ORDER_ADM_RIGHTS_INTO, 0, $refundOrderNo, [], [], $adminUid);
            }

            return $result;

        } catch (\Exception $e) {

            tLog::refund_rights_warning('管理员维权介入出现异常', [
                'params' => [
                    'admin_uid' => $adminUid,
                    'refund_order_no' => $refundOrderNo,
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile()
                ]
            ]);

            throw $e;
        }
    }

    public static function admRightsJudge($adminUid, $refundOrderNo, $data)
    {
        try {
            $result = mOrderRefund::action(function () use ($adminUid, $refundOrderNo, $data) {
                $clsAdmOrderRefund = new clsAdmOrderRefund();

                $result = $clsAdmOrderRefund->rightsJudge($adminUid, $refundOrderNo, $data);

                return $result;
            });

            if ($result !== false) {
                //记录OPERATE_LOG
                sOperateLog::record(mOperateLog::TYPE_REFUND_ORDER_ADM_RIGHTS_JUDGE, 0, $refundOrderNo, [], $data, $adminUid);

                return true;
            }

        } catch (\Exception $e) {

            tLog::refund_rights_warning('管理员维权判定出现异常', [
                'params' => [
                    'admin_uid' => $adminUid,
                    'refund_order_no' => $refundOrderNo,
                    'data' => $data
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile(),
                    'line' => $e->getLine()
                ]
            ]);

            throw $e;
        }
    }

    public static function admSearchOrderRefundList($params, $limit)
    {
        $search = new clsAdmOrderRefundSearch($params, $limit);

        return [
            'total' => $search->getCount(),
            'list' => $search->getList()
        ];

    }

    public static function admGetDetail($refundOrderNo)
    {
        $result = (new clsAdmOrderRefund())->fetchDetail($refundOrderNo);

        return $result;
    }

    public static function admGetRefundLogList($refundOrderNo)
    {
        $list = (new clsAdmOrderRefund())->getLogList($refundOrderNo);
        return $list;
    }


    public static function admGetRightsLogList($refundOrderNo)
    {
        $list = (new clsAdmOrderRefund())->getRightsLogList($refundOrderNo);
        return $list;
    }


    public static function admSearchOrderRightsList($params, $limit)
    {
        $search = new clsAdmOrderRightsSearch($params, $limit);

        return [
            'total' => $search->getCount(),
            'list' => $search->getList()
        ];

    }

    public static function admCalRefundAmount($refundOrderNo, $refundAmount)
    {
        try {
            $clsAdmOrderRefund = new clsAdmOrderRefund();

            $data = $clsAdmOrderRefund->calRefundAmount($refundOrderNo, $refundAmount);

            return $data;
        } catch (\Exception $e) {
            throw $e;
        }
    }

    public static function admRefundGroupBuy($adminUid, $orderNo)
    {
        try {
            clsOrderGroupBuy::cancelAndRefundOrder($orderNo, $adminUid, clsOrderGroupBuy::OP_TYPE_HAND);

        } catch (\Exception $e) {
            tLog::groupbuy_refund_warning('管理员手动取消团购订单失败', [
                'params' => [
                    'admin_uid' => $adminUid,
                    'order_no' => $orderNo,
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile(),
                    'line' => $e->getLine()
                ]
            ]);
            throw $e;
        }
    }

    public static function sysRefundGroupBuy($orderNo)
    {
        try {
            clsOrderGroupBuy::cancelAndRefundOrder($orderNo, 0, clsOrderGroupBuy::OP_TYPE_SYS);

        } catch (\Exception $e) {
            tLog::groupbuy_refund_warning('系统同自动取消团购订单失败', [
                'params' => [
                    'admin_uid' => 0,
                    'order_no' => $orderNo,
                ],
                'exception' => [
                    'code' => $e->getCode(),
                    'msg' => $e->getMessage(),
                    'file' => $e->getFile(),
                    'line' => $e->getLine()
                ]
            ]);
            throw $e;
        }
    }

    /**
     * 根据条件调用es
     * @param $params
     * @param $limit
     * @return array|mixed
     */
    public static function admGetRefundOrderNos($params, $limit)
    {
        if (isset($params['order_no']) && $params['order_no']) {
            $orderNo = $params['order_no'];
            unset($params);
            $params['order_no'] = $orderNo;
        }

        if (isset($params['refund_order_no']) && $params['refund_order_no']) {
            $refundNo = $params['refund_order_no'];
            unset($params);
            $params['refund_order_no'] = $refundNo;
        }

        //  如果有买家昵称或者商家名称的话，需要先根据名称获得id
        if (!empty($params['shop_name'])) {
            $results = AdmUserSearch::getUserIdsByFilter(['user_type' => [Member::AUTH_USER_BRAND], 'nick' => $params['shop_name']], 1);
            if ($results['rows']) {
                $params['shop_id'] = $results['rows'];
            }
            unset($params['shop_name']);
        }
        if (!empty($params['nick'])) {
            $results = AdmUserSearch::getUserIdsByFilter(['user_type' => [Member::USER_COMMON], 'nick' => $params['nick']], 1);
            if ($results['rows']) {
                $params['uid'] = $results['rows'];
            }
            unset($params['nick']);
        }
        $refundOrderNos = searchOrderRefund::getList($params, searchOrderRefund::SCENES_SHOP_ADMIN_ORDER_REFUND, 1, $limit[0], $limit[1], 'refund_order_no');
        return $refundOrderNos;
    }

    /**
     * 根据条件调用es
     * @param $params
     * @param $limit
     * @return array|mixed
     */
    public static function admGetRightRefundOrderNos($params, $limit)
    {
        if (isset($params['order_no']) && $params['order_no']) {
            $orderNo = $params['order_no'];
            unset($params);
            $params['order_no'] = $orderNo;
        }

        if (isset($params['refund_order_no']) && $params['refund_order_no']) {
            $refundNo = $params['refund_order_no'];
            unset($params);
            $params['refund_order_no'] = $refundNo;
        }
        if (isset($params['exclude']) && in_array('only_timeout', $params['exclude'])) {
            $params['only_timeout'] = 1;
            unset($params['exclude']);
        }
        $refundOrderNos = searchOrderRefund::getList($params, searchOrderRefund::SCENES_SHOP_ADMIN_ORDER_RIGHT, 1, $limit[0], $limit[1], 'refund_order_no');
        return $refundOrderNos;
    }
}